package com.chixing.controller;

import com.chixing.pojo.MyCoupon;
import com.chixing.pojo.MyOrder;
import com.chixing.service.MyCouponService;
import com.chixing.util.ServerResponse;
import org.bouncycastle.math.raw.Mod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;

/**
 * @author 马博
 * * @date 2021/10/6
 */
@Controller
public class MyCouponController {
    @Autowired
    private MyCouponService myCouponService;
    @GetMapping("coupon/toCoupon")
    public ModelAndView toCoupon(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("coupon/get_coupon");
        return modelAndView;
    }

    @GetMapping("myCoupon/{custId}")
    public ModelAndView getCustomerCoupon(@PathVariable("custId") Integer custId){
        ServerResponse serverResponse = myCouponService.getCustomerCoupon(custId);
        ModelAndView mav = new ModelAndView();
        mav.addObject("serverResponse",serverResponse);
        mav.setViewName("coupon/my_coupon");
        return mav;
    }

    //添加我的优惠券
    @PostMapping("createMyCoupon")
    public ModelAndView saveMyCoupon(Integer custId,
                                     Integer couponId){
        ServerResponse coupon = myCouponService.save(custId,couponId);
        ModelAndView mav = new ModelAndView();
        mav.addObject("myCoupon",coupon);
        mav.setViewName("coupon/get_coupon");
        return mav;
    }

}
